public class InsertionSort {
    //直接排序法
    void insertionSort(int[] arr){
        for (int i = 1; i < arr.length ; i++) {
            int temp=arr[i];
            int j;
            for (j = i-1; j >=0 ; j--) {
                if(arr[j]>temp){
                    arr[j+1]=arr[j];
                }else {
                    break;
                }
            }
            arr[j+1]=temp;
        }
    }
    public static void main(String[] args) {
        int[] arr = {45, 37, 63, 91, 26, 13, 58, 2};
        InsertionSort sort = new InsertionSort();
        sort.insertionSort(arr);
        for (int i : arr) {
            System.out.print(i + "\t");
        }
    }
}
